<?php

function getRecoverpass($error = null)

{
	
	
	
	
	 echo '<table class="changepass">';
    echo '<form method="post">
          <tr>
           <td>Username:</td>
           <td><input type="text" name="usern" placeholder="Tinkywinky" class="sexy"> </td>
          </tr>
          <tr>
           <td>Email:</td>
           <td><input type="text" name="email" placeholder="Tinkywinky@email.nl" class="sexy"></td>
         </tr>
         <tr>
           <td colspan="2"><font color="red">'.$error.' </font></td>
         </tr>
         </table>
         <p><input type="submit" value="Recover Pass"></p>
         </form>';
	
	
	
}

	function emailNewPass($email, $usern)
	{
		$newpass = randomKey(15);
		$updatepass = encrypt($newpass);
		
		if(mysql_query("UPDATE account SET password='$updatepass' WHERE email='$email' AND username='$usern'"))
		{
			$headers  = 'MIME-Version: 1.0' . "\r\n";
			$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

			$headers .= 'To: '.$email.'' . "\r\n";
			$headers .= 'From: MyLittleGangsters <mlg@jurienhamaker.net>' . "\r\n";
			
			$subject = '[MLG]MyLittleGangsters password reset';

			$body = '<b>Your new Password for MyLittleGangsters</b><br>';
			$body .= 'New password: '.$newpass.' <br>for the username: '.$usern.'.<br>';


			@mail($receiver, $subject, $body, $headers);
			echo '<font color="green">A new password has been send to the following email: '.$email.'.<br> Please check your spam folder.<br> Click <a href="index.php">Here</a> to go back.';
		}
		
		
	}
	
   function checkaccount($usern, $email)
  {
   	  
	
	$q = mysql_query("SELECT * FROM account WHERE username='$usern' AND email='$email'");
	
	if(mysql_num_rows($q) == 1)
	{
		emailNewPass($email, $usern);
	}
	else 
	{
		$error = 'Username and or email is not correct';
		getRecoverpass($error);
   }
  
  } 





?>